package com.tuyue.police.weixin.controller.page;

import com.tuyue.police.weixin.bean.UrlBean;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 王金海
 * @Description: 公众号菜单
 * @Date: Created by Administrator on 2018/3/20.
 * @Modified By:
 */
@RestController
@RequestMapping("/wechat/menu")
public class MenuController {

    @Autowired
    private WxMpService wxService;

    @GetMapping("menuCreate")
    public String menuCreate() throws WxErrorException {
        WxMenu menu = new WxMenu();
        WxMenuButton button = new WxMenuButton();
        button.setName("一键报警");
        button.setType(WxConsts.MenuButtonType.VIEW);
        button.setUrl(UrlBean.YJBJ);
        WxMenuButton button1 = new WxMenuButton();
        button1.setName("报警记录");
        button1.setType(WxConsts.MenuButtonType.VIEW);
        button1.setUrl(UrlBean.BJJL);
        WxMenuButton button2 = new WxMenuButton();
        button2.setName("个人中心");
        menu.getButtons().add(button);
        menu.getButtons().add(button1);
        menu.getButtons().add(button2);
        WxMenuButton button21 = new WxMenuButton();
        button21.setType(WxConsts.MenuButtonType.CLICK);
        button21.setName("绑定注册");
        button21.setKey("31");
        WxMenuButton button22 = new WxMenuButton();
        button22.setType(WxConsts.MenuButtonType.VIEW);
        button22.setName("个人资料");
        button22.setUrl(UrlBean.AUTHORIZEURL+UrlBean.GRZX);
        button2.getSubButtons().add(button21);
        button2.getSubButtons().add(button22);
        return wxService.getMenuService().menuCreate(menu);
    }
}
